package com.ps.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ps.property.PageBean;
import com.ps.property.ReviewQuestionVo;
import com.ps.service.ReviewQuestionService;
import com.ps.store.ReviewQuestionStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author gt
 * @类说明：
 * @date 2020/10/26 10:31
 */
@Service
public class ReviewQuestionServiceImpl implements ReviewQuestionService {
    @Autowired
    ReviewQuestionStore reviewQuestionStore;

    @Override
    public int reviewQuestionAdd(ReviewQuestionVo reviewQuestionVo) {
        return reviewQuestionStore.reviewQuestionAdd(reviewQuestionVo);
    }

    @Override
    public PageBean<ReviewQuestionVo> reviewQuestionQuery(int currentPage, int pageSize) {
        PageHelper.startPage(currentPage, pageSize,true);

        List<ReviewQuestionVo> list = reviewQuestionStore.reviewQuestionQuery();

        //通过这个pageInfo这个对象获取到查询总条数
        PageInfo pageInfo = new PageInfo(list);
        long total = pageInfo.getTotal();

        PageBean<ReviewQuestionVo> pageBean = new PageBean<>(currentPage,pageSize,total);
        pageBean.setData(list);

        return pageBean;
    }

    @Override
    public ReviewQuestionVo reviewQuestionQueryById(int reviewQuestionId) {
        return reviewQuestionStore.reviewQuestionQueryById(reviewQuestionId);
    }

    @Override
    public int reviewQuestionUpdate(ReviewQuestionVo reviewQuestionVo) {
        return reviewQuestionStore.reviewQuestionUpdate(reviewQuestionVo);
    }
}
